package sort;

import java.util.Arrays;

/**
 * 冒泡排序
 * 时间复杂度：O(n^2)
 * 空间复杂度：O(1)
 */
public class BubbleSort {
    public static void main(String[] args) {
        int[] nums = { 1, 4, 3, 10, 8, 7 };
        int[] ret = sort(nums);
        System.out.println(Arrays.toString(ret));

    }

    public static int[] sort(int[] nums) {
        int len = nums.length;
        for (int i = 0; i < len - 1; i++) {
            for (int j = 0; j < len - i - 1; j++) {
                if (nums[j] > nums[j + 1]) {
                    int tmp = nums[j];
                    nums[j] = nums[j + 1];
                    nums[j + 1] = tmp;
                }
            }
        }

        return nums;
    }
}
